package com.admgt.resource.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "loading_info")
public class LoadingInfo implements Serializable {
	private static final long serialVersionUID = 1L;
	private int id;
	private String loadType;// value: up or down.  up means upload, down mean down load.
	private String fileName;
	private String fileSize;
	private String hostName;
	private String loadStatus;
	private String localPath;
	private String serverPath;
	private int loadProgress;
	private Date updatedTime;
	@TableGenerator(
			name="PkGen",
			table="loading_info_gen",
			pkColumnName="PRIMARY_KEY",
			valueColumnName="LOADING_INFO",
			pkColumnValue="pkValue",
			allocationSize=1
	)
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="PkGen")
	@Column(name="ID",nullable=false)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	@Column(name="LOAD_TYPE",nullable=false)
	public String getLoadType() {
		return loadType;
	}
	public void setLoadType(String loadType) {
		this.loadType = loadType;
	}
	@Column(name="FILE_NAME",nullable=false)
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	@Column(name="FILE_SIZE",nullable=false)
	public String getFileSize() {
		return fileSize;
	}
	public void setFileSize(String fileSize) {
		this.fileSize = fileSize;
	}
	@Column(name="HOST_NAME",nullable=false)
	public String getHostName() {
		return hostName;
	}
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	@Column(name="LOAD_STATUS",nullable=false)
	public String getLoadStatus() {
		return loadStatus;
	}
	public void setLoadStatus(String loadStatus) {
		this.loadStatus = loadStatus;
	}
	@Column(name="LOCAL_PATH",nullable=false)
	public String getLocalPath() {
		return localPath;
	}
	public void setLocalPath(String localPath) {
		this.localPath = localPath;
	}
	@Column(name="SERVER_PATH",nullable=false)
	public String getServerPath() {
		return serverPath;
	}
	public void setServerPath(String serverPath) {
		this.serverPath = serverPath;
	}
	@Column(name="LOAD_PROGRESS",nullable=false)
	public int getLoadProgress() {
		return loadProgress;
	}
	public void setLoadProgress(int loadProgress) {
		this.loadProgress = loadProgress;
	}
	@Column(name="UPDATED_TIME", nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getUpdatedTime() {
		return updatedTime;
	}
	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}
	@Override
	public boolean equals(Object obj) {
		if(obj==null)return false;
		if(this==obj)return true;
		if(obj instanceof LoadingInfo){
			LoadingInfo other = (LoadingInfo)obj;
			return this.id == other.id;
		}
		return false;
	}
	@Override
	public int hashCode() {
		return id;
	}
	@Override
	public String toString() {
		String upload = "Upload file "+fileName+" to host"+hostName+ 
		". The status is "+loadStatus+ ". "+ loadProgress+"% of the taxk has been finished.";
		String download = "Download file "+fileName+" from host"+hostName+ 
		". The status is "+loadStatus+ ". "+ loadProgress+"% of the taxk has been finished.";
		return loadType.equalsIgnoreCase("up")?upload:download;
	}
	
	public Object[] toRowData() {
		Object[] rowData = {id,fileName,fileSize,hostName,loadStatus,
				localPath,serverPath,loadProgress,"N/A"};
		return rowData;
	}
	
	

}
